/**
 * @FileName: JDKProxyFactory.java
 * @Package: com.ziroom.sms.std.proxy
 * @author liusq23
 * @created 2017/3/10 上午9:28
 * <p>
 * Copyright 2015 ziroom
 */
package com.ziroom.sms.std.proxy;

import com.ziroom.sms.std.rpc.RpcInvocationHandler;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Proxy;

/**
 * <p></p>
 * <p>
 * <PRE>
 * <BR>	修改记录
 * <BR>-----------------------------------------------
 * <BR>	修改日期			修改人			修改内容
 * </PRE>
 *
 * @author liusq23
 * @version 1.0
 * @since 1.0
 */
public class JDKProxyFactory implements ProxyFactory {

<<<<<<< HEAD
=======

>>>>>>> bd63e2b592692e39f1d5d3b87848249c91ebc776
    /**
     * @param interfaces
     * @param <T>
     * @return
     */
    public <T> T getProxy(Class<T> interfaces, RpcInvocationHandler invocationHandler) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {
        Class<?> proxyClass = Proxy.getProxyClass(interfaces.getClassLoader(), interfaces);
        Constructor constructor = proxyClass.getConstructor(new Class[]{InvocationHandler.class});
        return (T) constructor.newInstance(invocationHandler);
    }


}
